import {
	mapMutations
} from 'vuex'

export default {
	...mapMutations([
		'upIndexInfo',
	]),
	confirm() {
		this.handlerChangeOrderType(0, 0)
	},
	handlerChangeOrderType(e, status) {
		this.current = e
		this.page = 1
		this.list = []
		this.orderStatus = status
		this.getPageList()
	},
	submitForm(e) {
		this.page = 1
		this.list = []
		this.getPageList()
	},
	getPageList() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'wechat/getMyOrderList',
			method: 'get',
			params: {
				orderStatus: that.orderStatus,
				page: that.page,
				list_rows: that.list_rows,
				keyword: that.keyword,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				}
			}
		})
	},
	confirmReceive(id) {
		let that = this
		that.$toast.confirm({
			content: `是否确认收货？`,
			confirmText: '确认',
			callback: result => {
				if (result) {
					that.$httpRequest.request({
						that: that,
						url: 'wechat/confirmReceive',
						method: 'post',
						params: {
							id
						},
						success: res => {
							if (res.code === that.$httpConfig.SUCCESS_CODE) {
								this.page = 1
								this.list = []
								this.getPageList()
							}
						}
					})
				}
			}
		})
	},
	toEvaluate(id) {
		uni.navigateTo({
			url: '/pages/my/evaluate?id=' + id
		})
	},
	getStatusStr(e) {
		let str = ''
		switch (e) {
			case 1:
				str = '待付款'
				break;
			case 2:
				str = '待发货'
				break;
			case 3:
				str = '待收货'
				break;
			case 4:
				str = '待评价'
				break;
			case 5:
				str = '退款中'
				break;
			case 6:
				str = '已退款'
				break;
			case 7:
				str = '已完成'
				break;
			default:
				break;
		}
		return str
	},
	// 预览图片
	previewImage(url, index) {
		uni.previewImage({
			current: index, // 当前显示图片的链接/索引值
			urls: [url], // 需要预览的图片链接列表，photoList要求必须是数组
			loop: true // 是否可循环预览
		});
	},
	toOrderDetail(id) {
		uni.navigateTo({
			url: '/pages/my/orderDetail?id=' + id + '&saleType=' + 0
		})
	},
	wechatPay(id) {
		let that = this
		this.loading = true;
		that.$httpRequest.request({
			that: that,
			url: 'wechat/orderPay',
			params: {
				id
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					// that.upSuccessPay(true)
					let data = res.data
					uni.requestPayment({
						timeStamp: data.timeStamp,
						nonceStr: data.nonceStr,
						package: data.package,
						signType: data.signType,
						paySign: data.paySign,
						success: res => {
							that.$toast.alert({
								content: '支付成功！',
								callback: result => {
									if (result.confirm) {
										uni.navigateBack({
											delta: 1
										})
									}
								}
							})
						}
					})
				} else {
					that.$toast.alert({
						content: res.msg,
						callback: result => {

						}
					})
				}
			}
		})

	},
}